﻿using System;
using System.Collections.Generic;
using System.Text;

namespace xReplace
{
    public class InvocationOptions
    {
        public enum InvocationSwitch
        {
            overrideSourcePath,
            overrideDestinationPath,
            overrideDestinationSingleFile,
            label
        }

        public class InvocationToken
        {
            public InvocationToken(InvocationSwitch token, string key, string setting)
            {
                this.m_key = key;
                this.m_setting = setting;
                this.m_token = token;
            }

            private InvocationSwitch m_token;
            public InvocationSwitch Token
            {
                get { return m_token; }
                set { m_token = value; }
            }

            private string m_key;
            public string key
            {
                get { return m_key; }
                set { m_key = value; }
            }

            private string m_setting;
            public string setting
            {
                get { return m_setting; }
                set { m_setting = value; }
            }
        }

        private System.Collections.Generic.List<InvocationToken> m_options;

        public InvocationOptions()
        {
            m_options = new List<InvocationToken>();
        }

        public void SetOption(InvocationOptions.InvocationSwitch token, string setting)
        {
            m_options.Add(new InvocationToken(token, "", setting));
        }


        public void SetOption(InvocationOptions.InvocationSwitch token, string key, string setting)
        {
            m_options.Add(new InvocationToken(token, key, setting));
        }

        public bool IsOptionSet(InvocationOptions.InvocationSwitch token)
        {
            for (int i = 0; i < m_options.Count; i++)
            {
                if (m_options[i].Token == token)
                    return true;
            }
            return false;
        }

        public KeyValuePair<string,string>[] GetOption(InvocationOptions.InvocationSwitch token)
        {
            List<KeyValuePair<string, string>> output = new List<KeyValuePair<string, string>>();
            for (int i = 0; i < m_options.Count; i++)
            {
                if (m_options[i].Token == token)
                    output.Add(new KeyValuePair<string,string>(m_options[i].key,m_options[i].setting));
            }
            return output.ToArray();
        }
    }
}
